home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: word vs. byte alignment option
- Message-ID: <marnoldDpn1Ax.4ox@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <4kdq3b$lhn@sloth.swcp.com>
- Date: Wed, 10 Apr 1996 08:37:45 GMT
- Sender: marnold@netcom23.netcom.com
-
- dvines@sparton.com (Dudley Vines) writes:
-
- >Anybody ever have trouble with Borland C++ compiler word vs. byte
- >alignment option? When I attempt to load a word aligned array into a byte
- >aligned array, the data in the byte aligned array is off by one byte.
-
- This is to be expected.
-
- >The arrays come from separate modules with different alignement options
- >set.
-
- >I thought the alignment option only affected speed or memory usage...why
- >doesn't the compiler figure out how to handle the data right?
-
- Alignment *primarily* affects the alignment of *data*, for the purposes
- of affecting speed and/or memory usage. Different alignment options
- can change how the complier lays out structs, for example. With word
- alignment, it may "pad" (insert dummy bytes) in between char members of
- a struct so they all align on word boundaries, for example. This is is
- why it's called "alignment".
-
- You can't compile to different pieces of code for differing alignments
- and expect them to be able to share data structures, unless you force
- some common alignment for those shared data struuctures. Having apparently
- not done this, the kinds of problems you are getting are no surprise.
-
- Why are you adjusting the alignment anyway? Do you have any concrete
- proof that some particular alignment will somehow improve the performance
- of you code? How much of that supposed time-savings has been wasted
- tracking down alignment-related bugs? Just a thought.
-
- First, get your code working. Second, identify possible performance
- issues. *Then* decide if a change in alignment is appropriate.
- Depending on CPU, compiler and type of code in your program, a change in
- alignment might be one of the least effective performance tuning options.
- It might even make things worse.
-
- Regards,
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-